﻿package com.riaidea.text {
    import flash.text.*;
    import flash.events.*;

    class TextRenderer extends TextField {

        private var _length:int = 0;
        private var _oldLength:int = 0;
        private var _scrollHeight:Number = 0;
        private var _defaultTextFormat:TextFormat;

        public function TextRenderer(){
            var _local1:TextFormat = new TextFormat("Arial", 12, 0, false, false, false);
            _local1.letterSpacing = 0;
            this.defaultTextFormat = _local1;
            this.multiline = true;
            this.wordWrap = true;
            this.type = TextFieldType.DYNAMIC;
        }
        override public function set text(_arg1:String):void{
            super.text = _arg1;
            this._length = this.length;
        }
        override public function set htmlText(_arg1:String):void{
            super.htmlText = _arg1;
            this._length = this.length;
        }
        override public function replaceText(_arg1:int, _arg2:int, _arg3:String):void{
            super.replaceText(_arg1, _arg2, _arg3);
            this._length = this.length;
        }
        override public function get defaultTextFormat():TextFormat{
            return (this._defaultTextFormat);
        }
        override public function set defaultTextFormat(_arg1:TextFormat):void{
            if (_arg1.letterSpacing == null){
                _arg1.letterSpacing = 0;
            };
            this._defaultTextFormat = _arg1;
            super.defaultTextFormat = _arg1;
        }
        override public function set type(_arg1:String):void{
            super.type = _arg1;
            this.addEventListener(Event.SCROLL, this.onScroll);
            if (type == TextFieldType.INPUT){
                this.addEventListener(Event.CHANGE, this.onTextChange);
                this.addEventListener(TextEvent.TEXT_INPUT, this.onTextInput);
            };
        }
        private function onScroll(_arg1:Event):void{
            this.calcScrollHeight();
        }
        private function onTextChange(_arg1:Event):void{
            this._oldLength = this._length;
            this._length = this.length;
        }
        private function onTextInput(_arg1:TextEvent):void{
            this.recoverDefaultFormat();
        }
        private function calcScrollHeight():void{
            if (this.length == 0){
                this._scrollHeight = 0;
                return;
            };
            var _local1:Number = 0;
            var _local2:int;
            while (_local2 < (this.scrollV - 1)) {
                _local1 = (_local1 + getLineMetrics(_local2).height);
                _local2++;
            };
            this._scrollHeight = _local1;
        }
        function recoverDefaultFormat():void{
            this.defaultTextFormat = this.defaultTextFormat;
        }
        function get scrollHeight():Number{
            return (this._scrollHeight);
        }
        public function get oldLength():int{
            return (this._oldLength);
        }
        function clear():void{
            this.text = "";
            this._oldLength = 0;
            this._scrollHeight = 0;
        }

    }
}//package com.riaidea.text 
